package com.qd.panda.wallet.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.panda.domain.entity.wallet.user.*;
import com.qd.common.sys.annotation.OperatorInfo;
import com.qd.common.sys.enums.OperatorType;
import com.qd.panda.service.wallet.user.UserWalletConsumptionLogService;
import com.qd.panda.service.wallet.user.UserWalletRechargeLogService;
import com.qd.panda.service.wallet.user.UserWalletRefundApplyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * 钱包/用户钱包/WEB_用户钱包
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/sys/wallet/userWallet/")
@Slf4j
public class WebUserWalletController {
    private final UserWalletRechargeLogService userWalletRechargeLogService;
    private final UserWalletConsumptionLogService userWalletConsumptionLogService;
    private final UserWalletRefundApplyService userWalletRefundApplyService;
    /**
     * 充值统计
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/rechargeStatistics")
    public UserWalletRechargeLogStatisticsDTO rechargeStatistics(UserWalletRechargeLogDTO dto) {
        return userWalletRechargeLogService.sumAmount(dto);
    }

    /**
     * 充值记录列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/rechargeLogPage")
    public IPage<UserWalletRechargeLogDTO> rechargeLogPage(UserWalletRechargeLogDTO dto) {
        return userWalletRechargeLogService.webPage(PageUtil.buildPage(dto), dto);
    }

    /**
     * 充值记录详情
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/rechargeLogGetById")
    public UserWalletRechargeLogDTO rechargeLogGetById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return userWalletRechargeLogService.getByIdDto(id);
    }

    /**
     * 充值记录导出
     *
     * @param query 查询参数
     */
    @PreAuthorize("@ps.hasPermission('system:userWalletRechargeLog:export')")
    @OperatorInfo(title = "导出", operator = OperatorType.EXPORT)
    @GetMapping(value = "/rechargeLogExport")
    public void rechargeLogExport(UserWalletRechargeLogDTO query) {
        userWalletRechargeLogService.export(query);
    }

    /**
     * 消费记录统计
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/consumptionStatistics")
    public UserWalletConsumptionLogStatisticsDTO consumptionStatistics(UserWalletConsumptionLogDTO dto) {
        return userWalletConsumptionLogService.sumAmount(dto);
    }

    /**
     * 消费记录列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/consumptionLogPage")
    public IPage<UserWalletConsumptionLogDTO> consumptionLogPage(UserWalletConsumptionLogDTO dto) {
        return userWalletConsumptionLogService.webPage(PageUtil.buildPage(dto), dto);
    }

    /**
     * 钱包消费记录详情
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/consumptionLogGetById")
    public UserWalletConsumptionLogDTO consumptionLogGetById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return userWalletConsumptionLogService.getByIdDto(id);
    }

    /**
     * 钱包消费记录导出
     *
     * @param query 查询参数
     */
    @PreAuthorize("@ps.hasPermission('system:userWalletConsumptionLog:export')")
    @OperatorInfo(title = "导出", operator = OperatorType.EXPORT)
    @GetMapping(value = "/consumptionLogExport")
    public void consumptionLogExport(UserWalletConsumptionLogDTO query) {
        userWalletConsumptionLogService.export(query);
    }

    /**
     * 钱包退款记录统计
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/refundStatistics")
    public UserWalletRefundApplyStatisticsDTO refundStatistics(UserWalletRefundApplyDTO dto) {
        return userWalletRefundApplyService.sumAmount(dto);
    }

    /**
     * 钱包退款记录列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/refundPage")
    public IPage<UserWalletRefundApplyDTO> refundPage(UserWalletRefundApplyDTO dto) {
        return userWalletRefundApplyService.page(PageUtil.buildPage(dto), dto);
    }

    /**
     * 钱包退款记录详情
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/refundGetById")
    public UserWalletRefundApplyDTO refundGetById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return userWalletRefundApplyService.getByIdDto(id);
    }

    /**
     * 钱包退款记录导出
     *
     * @param query 查询参数
     */
    @PreAuthorize("@ps.hasPermission('system:userWalletRefundApply:export')")
    @OperatorInfo(title = "导出", operator = OperatorType.EXPORT)
    @GetMapping(value = "/refundExport")
    public void refundExport(UserWalletRefundApplyDTO query) {
        userWalletRefundApplyService.export(query);
    }
}